package com.pureut.production.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.FeedRecord;
import com.pureut.production.domain.FeedRecordDetails;
import com.pureut.production.domain.dto.FeedRecordDetailsDto;
import com.pureut.production.domain.dto.FeedRecordDto;
import com.pureut.production.domain.vo.FeedRecordVo;
import com.pureut.production.domain.vo.FeedRecordmoVo;
import com.pureut.production.service.IFeedRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 投料记录
 * @Param FeedRecord
 * @Date 23-02-15
 * @Author hl
 **/
@RestController
@RequestMapping("/feedRecord")
public class FeedRecordController extends BaseController {

    @Resource
    private IFeedRecordService feedRecordService;

    /**
     * 投料记录查询
     */
    @RequiresPermissions("productionTube:prostatistics:feeding:list")
    @GetMapping("/list")
    public TableDataInfo list(FeedRecordVo feedRecordVo)
    {
        startPage();
        List<FeedRecordDto> list = feedRecordService.selectFeedRecordList(feedRecordVo);
        return getDataTable(list);
    }

    /**
     * 新增投料记录
     */
    @Log(title = "投料记录", businessType = BusinessType.INSERT)
    @PostMapping("/addFeed")
    public AjaxResult add(@Validated @RequestBody FeedRecord feedRecord){
        return toAjax(feedRecordService.insertFeedRecord(feedRecord));
    }

    /**
     * 删除投料记录
     */

    @Log(title = "投料记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{feedId}")
    public AjaxResult remove(@PathVariable("feedId") long feedId){
        return toAjax(feedRecordService.deleteFeedRecordById(feedId));
    }

    /**
     * 投料记录明细查询
     */
    @GetMapping("/listDetails/{feedId}")
    public TableDataInfo listDetails(@PathVariable long feedId)
    {
        startPage();
        List<FeedRecordDetailsDto> list = feedRecordService.selectFeedRecordDetailsList(feedId);
        return getDataTable(list);
    }

    /**
     * 投料记录明细新增
     */
    @PostMapping("/addDetails")
    @Log(title = "投料记录明细", businessType = BusinessType.INSERT)
    public AjaxResult addDetails(FeedRecordDetails feedRecordDetails)
    {
        return toAjax(feedRecordService.insertFeedRecordDetails(feedRecordDetails));
    }   

    /**
     * 投料统计
     */
    @RequiresPermissions("productionTube:produAdm:prostatistics:feeding:feedingStatistics")
    @GetMapping("/statistics/{feedId}")
    public AjaxResult statistics(@PathVariable long feedId)
    {
        return AjaxResult.success(feedRecordService.selectFeedRecordStatistics(feedId));
    }

    /**
     * 扫码投料
     */
    @PostMapping("/feed")
    @Log(title = "扫码投料", businessType = BusinessType.INSERT)
    @RequiresPermissions("productionTube:produAdm:prostatistics:feeding:productionFeeding")
    public AjaxResult feed(@RequestBody FeedRecordmoVo feedRecordmoVo)
    {
        return AjaxResult.success(feedRecordService.feed(feedRecordmoVo));
    }

    /**
     * 扫码撤销
     */
    @PostMapping("/feedRepeal")
    @Log(title = "扫码撤销", businessType = BusinessType.INSERT)
    public AjaxResult feedRepeal(@RequestBody FeedRecordmoVo feedRecordmoVo)
    {
        return AjaxResult.success(feedRecordService.feedRepeal(feedRecordmoVo));
    }

    /**
     * 投料记录明细查询
     */
    @GetMapping("/getInfo")
    public boolean getInfo(String moNumber)
    {

        return feedRecordService.getInfo(moNumber);

    }

    /**
     * 通过物料号码查询投料记录明细(物料履历)
     *
     * @param materialNumber
     * @return
     */
    @GetMapping("/getMaterialNumberInfo")
    public AjaxResult getMaterialNumberInfo(String materialNumber) {
        return AjaxResult.success(feedRecordService.getMaterialNumberInfo(materialNumber));
    }
}
